package leetcode.tree;

/**
 * @author MaoLin Wang
 * @date 2020/2/1416:02
 */
public class _100IsSameTree {
    public static boolean isSameTree(TreeNode p, TreeNode q) {
        if (p==null&&q==null){
            return true;
        }
        if (p==null||q==null){
            return false;
        }
        return compare(p,q);
    }

    private static boolean compare(TreeNode p, TreeNode q) {
        while (p!=null&&q!=null){
            if (p.val==q.val){
                boolean left = compare(p.left, q.left);
                boolean right = compare(p.right, q.right);
                return left&&right;
            }else {
                return false;
            }
        }
        if (p==null&&q==null){
            return true;
        }else {
            return false;
        }
    }
}
